<template>
  <div>
    <hd titles='我的收藏'></hd>
    <h5 class="no-tip" v-if="collectionItemData.length === 0">暂时没有收藏喔</h5>
    <template v-else>
      <CollectionItem v-for="item in collectionItemData" :key="item.id" :itemData="item" @faCancel="cancelStar"/>

      <van-divider
        :style="{ color: '#808080', borderColor: '#808080', padding: '0' }">
        亲，我也是有底线的
      </van-divider>
    </template>
  </div>
</template>

<script>
import CollectionItem from "@/components/gjj/CollectionItem";

import hd from '@/components/public/hd';
import classGoodsVue from '../components/xyl/classification/classGoods.vue';

//模拟数据
var collectionItemData = [
  {
    id:1,
    img: "../../static/images/6.jpg",
    title: "【仅限深圳同城地区】新鲜水果上市 大荔冬枣  5斤/箱 新鲜上市",
    tuan: "2人团",
    price: "¥ 75.00",
    state: "去开团",
  },
  {
    id:2,
    img: "../../static/images/6.jpg",
    title: "【仅限深圳同城地区】新鲜水果上市 大荔冬枣  5斤/箱 新鲜上市",
    tuan: "3人团",
    price: "¥ 75.00",
    state: "去开团",
  },
  {
    id:3,
    img: "../../static/images/6.jpg",
    title: "【仅限深圳同城地区】新鲜水果上市 大荔冬枣  5斤/箱 新鲜上市",
    tuan: "4人团",
    price: "¥ 75.00",
    state: "去开团",
  },
];

export default {
  name: "Collection",
  data() {
    return {
      collectionItemData: [],
    };
  },
  components: {
    CollectionItem,
    'hd':hd 
  },
  created() {
    this.getDataStore();
    // this.$store.commit({
    //   type: "selectById",
    //   formName:'group',
    //   id:this.ss[0].gid
    // })
    // this.pp = this.$store.state.res
    
  },
  methods: {
    getData() {
      this.collectionItemData = collectionItemData;
      // // 收藏表的数据
      // let collection = this.$store.state.collection;
      // // 拼团商品数据
      // let group = this.$store.state.group;

      // let currentGroup;

      // for(g of group){
      
      // }

      // console.table(group)
    },
    getDataStore(){
      console.log('aaa')
      let uid = this.$store.state.curLoginUser.id;
      let collections = this.$store.state.collection.filter((item)=>{
        return item.uid === uid;
      })
      
      for(let c of collections){
        for(let comd of this.$store.state.commodities){
          if(c.sid === comd.id){
            c.comodity = comd;
            break; 
          }
        }
        for(let g of this.$store.state.group){
          if(c.gid === g.id){
            c.group = g;
            break;
          }
        }
      }
      this.collectionItemData = collections;
    },
    // 取消收藏
    cancelStar(id){
      this.$store.commit({
        type:'delById',
        formName:'collection',
        id:id
      })
      this.getDataStore();
      console.log(this.collectionItemData);
    }
    
  },
};
</script>

<style scope>
 .no-tip {
   position: absolute;
   top: 40%;
   left:50%;
   transform: translate(-50%,-50%);
   color: #aaa;
   font-size: 25px;
 }
</style>